<!-- 模板继承 -->
{extend name="public:base" /}

<!-- 页面标题 -->
{block name="title"}Administrator{/block}

<!-- 自定义css -->
{block name="css"}{/block}

<!-- 内容区域 -->
{block name="content"}
  <div class="nav-tabs-custom">
    <ul class="nav nav-tabs">
      <li class="active"><a href="#">{:lang('Document')}</a></li>
      <li class=""><a href="{:url('admin/document/create')}">{:lang('Create')}</a></li>
    </ul>

    <div class="box box-solid">
        <div class="box-header with-border">
          <h3 class="box-title">{:lang('Filter')}</h3>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
            <form action="#" method="get" class="form-inline">
              <div class="form-group">
                  <div class="input-group">
                  <span class="input-group-addon" id="basic-addon1">{:lang('List')}</span>
                  <select name="cid" class="form-control">
                    <option>--{:lang('Any')}--</option>
                    <option {eq name="search.cid" value="0"}selected{/eq} value="0">--{:lang('Not specified')}--</option>
                    {volist name="category" id="vo"}
                    <option {eq name="vo.id" value="$search.cid"}selected{/eq} value="{$vo.id}">
                        {eq name="vo.pid" value="0"}
                            {$vo.title}
                        {else/}
                            {$vo.html} {$vo.title}
                        {/eq}
                    </option>
                    {/volist}
                  </select>
                  </div>
              </div>
              <div class="form-group">
                  <div class="input-group">
                  <span class="input-group-addon" id="basic-addon1">{:lang('Type')}</span>
                  <select name="option" class="form-control">
                    <option value="0">--{:lang('Any')}--</option>
                    {foreach $option as $k=>$v } 
                    <option {eq name="k" value="$search.option"}selected{/eq} value="{$k}">
                        {:lang($v)}
                    </option>
                    {/foreach}
                  </select>
                  </div>
              </div>
              <div class="form-group">
                <input type="text" name="q" value="{$search.q}" class="form-control" placeholder="">
              </div>
              <button type="submit" class="btn btn-primary btn-flat"> <i class="fa fa-search"></i> {:lang('Search')}</button>
            </form>
        </div>
        <!-- /.box-body -->
    </div>

    <div class="tab-content">
        <div class="tab-pane active table-responsive no-padding">
            <table class="table table-condensed table-hover">
                <thead>
                    <tr>
                        <th><input id="checkAll" type="checkbox"></th>
                        <th>#ID</th>
                        <th>{:lang('Title')}</th>
                        <th>{:lang('Page view')}</th>
                        <th>{:lang('Status')}</th>
                        <th>{:lang('Creation date')}</th>
                        <th>{:lang('Action')}</th>
                    </tr>
                </thead>
                <tbody>
                    {volist name="list" id="vo"}
                    <tr id = "tr_{$vo.id}">
                        <td><input name="ids[]" value="{$vo.id}" type="checkbox"></td>
                        <td>{$vo.id}</td>
                        <td>
                            {$vo.title}
                            {eq name="vo.image_flag" value="1"}
                                <small class="label bg-gray">{:lang('Image')}</small>
                            {/eq}
                            {eq name="vo.video_flag" value="1"}
                                <small class="label bg-gray">{:lang('Video')}</small>
                            {/eq}
                            {eq name="vo.attach_flag" value="1"}
                                <small class="label bg-gray">{:lang('Attach')}</small>
                            {/eq}
                            {eq name="vo.hot_flag" value="1"}
                                <small class="label bg-gray">{:lang('Hot')}</small>
                            {/eq}
                            {eq name="vo.recommend_flag" value="1"}
                                <small class="label bg-gray">{:lang('Recommend')}</small>
                            {/eq}
                            {eq name="vo.focus_flag" value="1"}
                                <small class="label bg-gray">{:lang('Focus')}</small>
                            {/eq}
                            {eq name="vo.top_flag" value="1"}
                                <small class="label bg-gray">{:lang('Top')}</small>
                            {/eq}
                        </td>
                        <td>{$vo.pv}</td>
                        <td>
                            {switch vo.status}
                                {case 1}<small class="label bg-light-blue">{:lang('Approval')}</small>{/case}
                                {case 0}<small class="label bg-gray">{:lang('Progress')}</small>{/case}
                                {default /}
                            {/switch}
                        </td>
                        <td>{$vo.create_at}</td>
                        <td>
                            <a href="{:url('admin/document/edit', ['id' => $vo['id']])}"></i> {:lang('Edit')}</a>
                            <a onclick="remove('{$vo.id}')" href="#"> {:lang('Delete')}</a>
                        </td>
                    </tr>
                    {/volist}
                    {empty name="list"}
                    <tr>
                        <td colspan="7" class="text-center">{:lang("No record")}</td>
                    </tr>
                    {/empty}
                </tbody>
            </table>
        </div>
        <!-- /.tab-pane -->
    </div>
    <!-- /.tab-content -->
    <div class="box-footer">
        <div class="row">
          <div class="col-md-6">
            <form method="post" class="form-inline">
                <div class="input-group">
                    <div><select id="type" class="form-control">
                        <option value="approval">{:lang('Approval')}</option>
                        <option value="progress">{:lang('Progress')}</option>
                        <option value="delete">{:lang('Delete')}</option>
                    </select>
                    </div>
                    <span class="input-group-btn"> 
                        <button type="button" onclick="handle()" class="btn btn-primary btn-flat"> {:lang('Save')} </button> 
                    </span>
                </div>
            </form>
          </div>
          <div class="col-md-6">
            <div class="text-right"> {$page} </div>
          </div>
        </div>
    </div>
  </div>


{/block}

<!-- 自定义js -->
{block name="js"}
<script type="text/javascript">
    //批量操作
    function handle(){
        var chk_value =[]; 
        $('input[name="ids[]"]:checked').each(function(){ 
            chk_value.push($(this).val()); 
        }); 
        var type = $('#type option:selected').val() ;
        if(chk_value.length < 1){
            swal({
                title: "{:lang('No record selected')}",
                text: "",
                type: "warning"
            });
        }else{
            swal({
              title: "{:lang('Are you sure')}",
              type: "warning",
              showCancelButton: true,
              confirmButtonColor: '#3085d6',
              cancelButtonColor: '#d33',
              confirmButtonText: "{:lang('Yes')}",
              cancelButtonText: "{:lang('No')}",
            }).then(function(result){
              if (result.value) {
                $.ajax({
                    url:"{:Url('admin/document/handle')}",
                    data:{'ids':chk_value, 'type':type},
                    type:'post',
                    dataType:'json',
                    success: function(xhr){
                        if(xhr.code == 200){
                            swal(xhr.msg, "","success").then(function(value){
                              window.location.reload();
                            });
                        }else{
                            swal(xhr.msg, "", "error");
                        }
                    }
                })
              }
            })
        }
    }

    function remove(id){
        swal({
          title: "{:lang('Are you sure')}",
          type: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: "{:lang('Yes')}",
          cancelButtonText: "{:lang('No')}",
        }).then(function(result){
          if (result.value) {
            $.ajax({
                url:"{:Url('admin/document/remove')}",
                data:{'id':id},
                type:'post',
                dataType:'json',
                success: function(xhr){
                    if(xhr.code == 200){
                        swal(xhr.msg, "","success").then(function(value){
                            $("#tr_" + id).remove();
                        });
                    }else{
                        swal(xhr.msg, "", "error");
                    }
                }
            })
          }
        })
    }
</script>
{/block}